<template>
  <div>
    <div style="margin-top:20px; clear:both;">
      <label>
        <input v-model='isActive' type="checkbox" @change="CheckAll" />
        &emsp;{{hanType(item.type)}}
      </label>
      <div class="shop-list">
        <dl v-for="(v,i) in item.children" :key="i">
          <dd>
            <img style="width:100%;display:block;" :src="v.img" alt />
          </dd>
          <dt style="text-align:center;">
            {{v.name}}
            <br />
            <input type="checkbox" @change="checkFun" :value='v.name' v-model="childrenValue" />
          </dt>
        </dl>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["item"],
  data() {
    return {
      childrenValue: [],
      isActive: false
    };
  },
  methods: {
    hanType(value) {
      switch (value) {
        case 1:
          return "学习用品";
        case 2:
          return "生活用品";
        case 3:
          return "体育用品";
        case 4:
          return "野炊用品";
        case 5:
          return "医学用品";
      }
    },
    checkFun() {
      if (this.childrenValue.length == this.item.children.length) {
        this.isActive = true;
      } else {
        this.isActive = false;
      }
    },
    CheckAll() {
      if (this.isActive) {
        this.childrenValue = this.item.children.map(v => {
          return v.name;
        });
      } else {
        this.childrenValue = [];
      }
    }
  }
};
</script>

<style scoped>
* {
  padding: 0;
  margin: 0;
}
.shop-list dl {
  padding-left: 20px;
  padding-top: 10px;
  float: left;
  width: 120px;
}
</style>